package com.ohuang.demo

import android.os.Bundle
import android.util.Log
import android.view.View
import android.webkit.WebView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import com.ohuang.demo.webView.SteamDbWebView
import com.ohuang.demo.webView.SteamWebView
import kotlinx.coroutines.launch
import java.io.File

class WebActivity : AppCompatActivity() {
    private  val TAG = "WebActivity"
    var steamWebView= SteamWebView()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_web)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        WebView.setWebContentsDebuggingEnabled(true)
        val webView = findViewById<WebView>(R.id.my_webview)
        steamWebView.initWebView(webView)
        steamWebView.startRegisterKey("xx")

//        lifecycleScope.launch {
//            val html=steamWebView.loadUrlInfo("https://steamdb.info/app/730/stats/")
//            Log.d(TAG, "onCreate: "+html)
//            File(cacheDir.absolutePath+"/a.html").writeText(html)
//        }


    }

    override fun onDestroy() {
        super.onDestroy()
        steamWebView.onDestroy()
    }
}